<?php



include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/album/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tuijian/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/gonglue/inc.php");
ob_start();


//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	cgi::both($g_cgival["p"], "p", "1");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	$topic_id = $config["current_site_id"];
	
	$g_cgival["pcount"]= 100;
	$db_mblog_pic_content = new db_mblog_pic_content();
	$db_mblog_meinv_content = new db_mblog_meinv_content();
	$db_mblog_video_content = new db_mblog_video_content();
	
	
	if($topic_id)
	{
	
		
		$mblog_list = $db_mblog_pic_content->get_mblog_pubu_list_by_topic($g_cgival["p"],$g_cgival["pcount"],$topic_id );
		
		$mblog_content ="<ul>";
		foreach($mblog_list as $value)
		{
			$mblog_content .= "<li><a href='/mblog/detail_{$value["id"]}.html'>{$value["content"]}</a><li>";
		}
		$mblog_content .= "<ul>";
		
		
		$video_list = $db_mblog_video_content->get_mblog_video_list_by_topic($g_cgival["p"],$g_cgival["pcount"] ,$topic_id);
		
		if($video_list)
		{
			$mblog_content .="<ul>";
			foreach($video_list as $value)
			{
				$mblog_content .= "<li><a href='/video/detail_{$value["id"]}.html'>{$value["content"]}</a><li>";
			}
			$mblog_content .= "<ul>";
		
		}
			
		$count = $mblog_list = $db_mblog_pic_content->get_mblog_pubu_count_by_topic($topic_id);
	}	
	else 
	{
		
		$mblog_list = $db_mblog_meinv_content->get_mblog_pubu_list_by_topic($g_cgival["p"],$g_cgival["pcount"] );
		
		$mblog_content ="<ul>";
		foreach($mblog_list as $value)
		{
			$mblog_content .= "<li><a href='/meinv/detail_{$value["id"]}.html'>{$value["content"]}</a><li>";
		}
		$mblog_content .= "<ul>";
		
		$count = $mblog_list = $db_mblog_meinv_content->get_mblog_pubu_count_by_topic();
		
	}
	
	
	$g_show["count"] = $count;
	
	
	$Pages = new Pages($g_show["count"] ,$g_cgival["p"],$g_cgival["pcount"]);
	$g_show["page_bar"] = $Pages->getLinks_static("/sitemap_replacepage.html",10);
	
	echo <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>游戏美图-sitemap</title>
<meta content="游戏,分享,图片,玩家,攻略,视频,游戏视频" name="keywords">
 <meta content="游戏美图-sitemap" name="description">
 </head>
 <body>
 {$mblog_content}
 
 {$g_show["page_bar"]} 
 </body>
 </html>
EOF;
	
	exit;
	
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("index.html");

	if(isset($_GET["reload"]))
	{
		$res= ob_get_contents();
		//file_put_contents("index.html",$res);
	
	}	
	
	
	
	if($_GET["debug"])
	{
		echo "<pre>";
		print_r($g_show);
	}
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

